﻿using AutomaticScrewLocking.domain.dataStorage.repository;
using AutomaticScrewLocking.infrastructure.pojo;
using MySql.Data.MySqlClient;
using System;
using System.Data;


namespace AutomaticScrewLocking.infrastructure.repository
{
    public class TorqueRepository : ITorqueRepository
    {
        public DataSet queryTorqueList(TorquePoJo torque)
        {
            DateTime startTime = torque.startTime;
            DateTime endTime = torque.endTime;
            MySqlParameter[] mySqlParameters = new MySqlParameter[2];
            mySqlParameters[0] = new MySqlParameter("@start_time", startTime);
            mySqlParameters[1] = new MySqlParameter("@end_time", endTime);
            string sql = "select torque_value from torque where create_time >=@start_time and create_time <=@end_time";
            DataSet dataSet = SqlHelper.getDataSet(sql, mySqlParameters);
            return dataSet;
        }

        public int saveTorqueData(double maxTorque,DateTime createTime)
        {
            MySqlParameter[] mySqlParameters = new MySqlParameter[2];
            mySqlParameters[0] = new MySqlParameter("@max_torque", maxTorque);
            mySqlParameters[1] = new MySqlParameter("@create_time", createTime);
            string sql = "insert into torque(torque_value,create_time) values(@max_torque,@create_time)";
            int rows = SqlHelper.executeSql(sql,mySqlParameters);
            return rows;
        }
    }
}
